package com.itheima.controller;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.ICheckgroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-19
 */
@RestController
@RequestMapping("/checkgroup")
@Api(tags = "检查组管理")
@Slf4j
public class CheckgroupController {
    @Autowired
    private ICheckgroupService checkgroupService;

    @PostMapping("/findPage")
    @ApiOperation("分页查询")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询:{}",queryPageBean);
        PageResult pageResult = checkgroupService.findPage(queryPageBean);
        return pageResult;
    }
    @GetMapping("/findById")
    @ApiOperation("根据id查询检查组")
    public Result findById(@RequestParam("id") Integer id){
        CheckGroup checkGroup = checkgroupService.findById(id);
        return new Result(true,"查询成功",checkGroup);
    }
    @PostMapping("/add")
    @ApiOperation("新增检查组")
    public Result add(@RequestBody CheckGroup checkGroup,@RequestParam("checkitemIds") List<Integer> checkItemIds){
        log.info("新增检查组:{}",checkGroup,checkItemIds);
        checkgroupService.add(checkGroup,checkItemIds);
        return new Result(true,"新增成功");
    }
    @PostMapping("/edit")
    @ApiOperation("编辑检查组")
    public Result edit(@RequestBody CheckGroup checkGroup,@RequestParam("checkitemIds") List<Integer> checkItemIds){
        log.info("编辑检查组:{}",checkGroup,checkItemIds);
        checkgroupService.edit(checkGroup,checkItemIds);
        return new Result(true,"编辑成功");
    }
    @GetMapping("/deleteById")
    @ApiOperation("根据id删除检查组")
    public Result deleteById(@RequestParam("id") Integer id){
        log.info("根据id删除检查组:{}",id);
        checkgroupService.deleteByCheckId(id);
        return new Result(true,"删除成功");
    }
    @GetMapping("/findAll")
    @ApiOperation("查询所有检查组")
    public Result findAll(){
        List<CheckGroup> checkGroups = checkgroupService.findAll();
        return new Result(true,"查询成功",checkGroups);
    }
    @GetMapping("/findCheckGroupIdsBySetmealId")
    @ApiOperation("根据套餐id查询检查组id")
    public Result findCheckGroupIdsBySetmealId(@RequestParam("setmealId") Integer id){
        List<Integer> checkGroupIds = checkgroupService.findCheckGroupIdsBySetmealId(id);
        return new Result(true,"查询成功",checkGroupIds);
    }

}
